package com.xkcyy.one.ai.common.tool;

import com.xkcyy.one.ai.llm.model.ToolDefinition;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * 默认工具注册表实现
 * 
 * @author yuand
 */
@Slf4j
public class DefaultToolRegistry implements ToolRegistry {
    private final Map<String, Tool> tools = new ConcurrentHashMap<>();

    @Override
    public void register(Tool tool) {
        tools.put(tool.getName(), tool);
        log.info("Registered tool: {}", tool.getName());
    }

    @Override
    public Tool findTool(ToolDefinition definition) {
        return tools.get(definition.getFunction().getName());
    }

    @Override
    public List<ToolDefinition> getAllToolDefinitions() {
        return tools.values().stream()
                .map(Tool::getDefinition)
                .collect(Collectors.toList());
    }
}